# -*- coding: utf-8 -*- 
"""
========================================================================================================================
@project : my-sanic
@file: myListener
@Author: mengying
@email: 652044581@qq.com
@date: 2023/3/3 13:36
@desc: 我的监听器, 监听服务启动或者关闭
========================================================================================================================
"""
from sanic import Sanic
from config import config
import os

app = Sanic.get_app(config.PROJECT_NAME)


@app.listener('after_server_start')
def notify_server_started(app, loop):

    banner = os.path.join(os.path.dirname(__file__), 'banner.txt')
    if os.path.exists(banner):
        with open(banner, "r", encoding="utf-8") as f:
            print(f.read())

    print("server listen on: %s", app.serve_location)